<?php
// Use the this array (or create new arrays with a different association) to replace
// setting fields in the form. Don't delete the 'default' array.

$formAction['default'] = array(
	'recipient' => '',
	'recipient_cc' => '',
	'recipient_bcc' => '',
	'subject' => '',
	'redirect' => '',
	'email' => '',
	'realname' => '',
	'required' => '',
	'format' => 'html',
	'sesrep_max_items' => '10',
);

// If set to 0, the form can set the email recipient. For security reasons you should
// set this variable to 1.

$disableFormRecipients = 1;

require('validate.php');

if(($_POST['form_action'] == '') || ($formAction[$_POST['form_action']]['recipient'] == '')) {
	$fAIndex = 'default';
} else {
	$fAIndex = $_POST['form_action'];
}

//$recipient  = (!$disableFormRecipients && ($_POST['femail'] != '')) ? $_POST['femail'] : $formAction[$fAIndex]['femail'];
//$subject  = ($_POST['subject'] != '') ? $_POST['subject'] : $formAction[$fAIndex]['subject'];
$redirect = ($_POST['redirect'] != '') ? $_POST['redirect'] : $formAction[$fAIndex]['redirect'];
//$email = ($_POST['uemail'] != '') ? $_POST['uemail'] : $formAction[$fAIndex]['uemail'];
//$realname = ($_POST['uname'] != '') ? $_POST['uname'] : $formAction[$fAIndex]['uname'];
$recipient_cc  = (!$disableFormRecipients && ($_POST['recipient_cc'] != '')) ? $_POST['recipient_cc'] : $formAction[$fAIndex]['recipient_cc'];
$recipient_bcc  = (!$disableFormRecipients && ($_POST['recipient_bcc'] != '')) ? $_POST['recipient_bcc'] : $formAction[$fAIndex]['recipient_bcc'];
$format = ($_POST['format'] != '') ? $_POST['format'] : $formAction[$fAIndex]['format'];
$required  = ($_POST['required'] != '') ? $_POST['required'] : $formAction[$fAIndex]['required'];
$sesrep_max_items  = ($_POST['sesrep_max_items'] != '') ? $_POST['sesrep_max_items'] : $formAction[$fAIndex]['sesrep_max_items'];
$recipient_secured  = ($_POST['recipient_secured'] != '') ? $_POST['recipient_secured'] : $formAction[$fAIndex]['recipient_secured'];
//$msg = ($_POST['msg'] != '') ? $_POST['msg'] : $formAction[$fAIndex]['msg'];


$subject = $uname . " thought you might like this video game.";
$email = $uemail;
$realname = $uname;
$recipient = $femail;

$msg = "Hi " . $fname . ",\n\n";
$msg .= $uname . " thought you might like the new Television Tunes video game called Name That Theme Song.\n\n";
$msg .= "You can check it out here:\nhttp://www.televisiontunes.com/ntts.html\n\n";
$msg .= $uname . " said:\n" . $message . "\n\n";
$msg .= "Hope you like Television Tunes!\n\nJay Campbell";


$rccArray = explode(",",$recipient_cc);
$recipient_cc = '';
if($rccArray[0] != '') {
	foreach($rccArray as $rcc) {
		$a = explode("@",$rcc);
		$a = array_pop($a);
		if(in_array($a,$validReferrers)) {
			$recipient_cc .= "$rcc,";
		}
	}
}
$recipient_cc = substr($recipient_cc,0,-1);

$rbccArray = explode(",",$recipient_bcc);
$recipient_bcc = '';
if($rbccArray[0] != '') {
	foreach($rbccArray as $rbcc) {
		$a = explode("@",$rbcc);
		$a = array_pop($a);
		if(in_array($a,$validReferrers)) {
			$recipient_bcc .= "$rbcc,";
		}
	}
}
$recipient_bcc = substr($recipient_bcc,0,-1);

/*if (! preg_match("/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i", $recipient, $result)) {echo "Invalid recipient"; exit;}*/
if (strlen($recipient) > 80 or strlen($recipient_cc) > 200 or strlen($recipient_bcc) > 200) {exit;}
if(stristr($subject, "Bcc:") or stristr($subject, "cc:")) {echo "Invalid content in subject"; exit;}
if(stristr($msg, "Bcc:") or stristr($msg, "cc:")) {echo "Invalid content in message"; exit;}
if(stristr($realname, "Bcc:") or stristr($realname, "cc:")) {echo "Invalid content"; exit;}
if(stristr($email, "Bcc:") or stristr($email, "cc:")) {echo "Invalid content"; exit;}

$extraHeaders = "";

if($email != '') { $extraHeaders .= "From: \"".addslashes($realname)."\" <". $email .">\r\n"; }
if($realname != '') { $extraHeaders .= "Reply-To:" . $email ."\r\n"; }
if($recipient_cc != '') { $extraHeaders .= "Cc: ". $recipient_cc ."\r\n"; }
if($recipient_bcc != '') { $extraHeaders .= "Bcc: ". $recipient_bcc ."\r\n"; }

$success = 1;
$success = mail($recipient,$subject,$msg,$extraHeaders);

echo "&sentOk=" . $success;
//header("Location: contact_thankyou.html"); 

?>